<!-- 账号信息设置 -->
<template>
	<view class="page" >
		<view class="content">
			<view class="user flex justify-between align-center">
				<view class="name">
					头像
				</view>
				<view class="userimg flex justify-center align-center" @click="isShowConfirmA = true">
					<view  class="img">
						<image :src="item.avatar" mode="scaleToFill"></image>
					</view>
					<u-icon size="30" color="#999999" name="arrow-right"></u-icon>
				</view>
			</view>
			<view class="user height flex justify-between align-center" @click.stop="isShowConfirm = true">
				<view class="name">
					昵称
				</view>
				<view class="userimg flex justify-center align-center">
					<text class="te1">{{item.nickname}}</text>
					<u-icon size="30" color="#999999" name="arrow-right"></u-icon>
				</view>
			</view>
			<view class="user height flex justify-between align-center">
				<view class="name">
					性别
				</view>
				<view class="userimg flex justify-center align-center" @click.stop="visible = true">
					<text class="te2" v-if="item.userGender">男</text>
					<text class="te2" v-if="!item.userGender">女</text>
					<u-icon size="30" color="#999999" name="arrow-right"></u-icon>
				</view>
			</view>
			<view class="user height flex justify-between align-center" @click.stop="isShowConfirmp = true">
				<view class="name">
					绑定手机
				</view>
				<view class="userimg flex justify-center align-center">
					<text class="te2">{{item.userPhone}}</text>
					<u-icon size="30" color="#999999" name="arrow-right"></u-icon>
				</view>
			</view>
		</view>
		<!-- 修改头像 -->
		<u-mask :show="isShowConfirmA" @click="isShowConfirmA = false">
			<view class="uploads flex justify-center flex-column align-center" @click.stop>
				<u-upload :header="header" :action="action" show-upload-list="false" max-count="1" name="path"
						class="image" custom-btn="true" @on-Success="onsuccess" deletable="false" width="180" height="180"
						show-progress="false" file-list="">
					<view slot="addBtn" style="width: 180rpx;height: 180rpx;">
						<image src="https://sanfuzhide.oss-cn-hangzhou.aliyuncs.com/my/tianjiaimg.png" mode=""></image>
					</view>
				</u-upload>
				<view class="but flex justify-center align-center" @click="setImg">
					确认
				</view>
			</view>
		</u-mask>
		<!-- 修改昵称 -->
		<u-mask :show="isShowConfirm" @click="isShowConfirm = false">
			<view class="setname" @click.stop>
				<view class="form flex align-center">
					<view class="name flex-shrink">
						昵称
					</view>
					<view class="input">
						<u-input custom-style="style" v-model="nickQurey.nickname" type="text" />
					</view>
				</view>
				<view class="but flex justify-center align-center" @click="confirmAcceptance1(nickQurey)">
					确认
				</view>
			</view>
		</u-mask>
		<!-- 修改手机号 -->
		<u-mask :show="isShowConfirmp" @click="isShowConfirmp = false">
			<view class="setname" @click.stop>
				<view class="form flex align-center">
					<view class="name flex-shrink">
						手机号
					</view>
					<view class="input">
						<u-input custom-style="style" v-model="phoneQurey.userPhone" type="number" />
					</view>
				</view>
				<view class="but flex justify-center align-center" @click="confirmAcceptance2(phoneQurey)">
					确认
				</view>
			</view>
		</u-mask>
		<!-- 滚动选择性别 -->
		<u-select confirm-color="#0265EB" v-model="visible" :list="list" @confirm="confirmAcceptance3" @cancel="visible=false"></u-select>
		<!-- <view class="select0" v-if="visible">
			<view class="bgc"></view>
			<view class="select1">
				<view class="sex">请选择性别</view>
				<view @click.stop="confirmAcceptance3(sexQurey)" class="confirm">确认</view>
			</view>
			<picker-view :indicator-style="indicatorStyle" :value="value" @change="bindChange" class="picker-view">
				<picker-view-column>
					<view class="item" v-for="(item,index) in sex" :key="index">{{item}}</view>
				</picker-view-column>
			</picker-view>
		</view> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				item: {},
				isShowConfirm: false,
				isShowConfirmp: false,
				isShowConfirmA:false,
				userPhone: '',
				nickQurey: {
					nickname: ''
				},
				phoneQurey: {
					userPhone: ''
				},
				avatarQurey: {
					avatar: ''
				},
				sexQurey: {
					userGender:Number
				},
				action: 'https://shanfu.51fnt.com/attentionList/uploadPicture',
				path: {
					path: 'path'
				},
				header: {
					'Content-Type': 'formData'
				},
				visible: false,
				list: [
					{
						value: 0,
						label: '女'
					},
					{
						value: 1,
						label: '男'
				}]
			}
		},
		onLoad() {
			this.getData()
		},
		methods: {
			//请求数据
			async getData() {
				let {
					data: item
				} = await this.$get('/user/UserInfo')
				this.item = item
			},
			//刷新页面
			fresh() {
				if (getCurrentPages().length != 0) {
					getCurrentPages()[getCurrentPages().length - 1].onLoad()
				}
			},
			//发送数据并刷新
			async postData(e) {
				await this.$post('/user/updateUserInfo', e)
				await this.getData()
			},
			confirmAcceptance1(e) {
				this.postData(e).then(()=>{
					uni.setStorageSync('nickName',e.nickname)
					this.isShowConfirm = false
				})
				
			},
			confirmAcceptance2(e) {
				let phoneCodeVerification = /^[1][3,4,5,7,8][0-9]{9}$/;
				if(phoneCodeVerification.test(e.userPhone)){
					this.postData(e).then(()=>{
					uni.setStorageSync('userPhone',e.userPhone)
					this.isShowConfirmp = false
				})
				}else{
					uni.showToast({
						title: '输入有误',
						icon: 'none'
					})
				}
				
				
			},
			confirmAcceptance3(e) {
				this.sexQurey.userGender = e[0].value
				this.postData(this.sexQurey).then(()=>{
					uni.setStorageSync('userGender',e.userGender)
					this.visible = false
				})
				
			},
			onsuccess(res) {
				console.log(res)
				this.avatarQurey.avatar = res.data.picture[0].url
			},
			setImg(){
				this.postData(this.avatarQurey).then(()=>{
					this.isShowConfirmA = false
					uni.setStorageSync('avatar',res.data.picture[0].url)
				})
			},
		},

	}
</script>

<style lang="scss">
	.page {
		background: #f5f5f5;
		min-height: 100vh;

		.content {
			padding: 0 30rpx;
			background-color: #FFFFFF;

			.user {
				height: 125rpx;
				border-bottom: 1rpx solid rgba(0, 0, 0, .12);

				.name {
					font-weight: 500;
					color: #222222;
					font-size: 31rpx;
				}

				.userimg {
					.te1 {
						font-size: 31rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #000001;
						line-height: 1;
					}

					.te2 {
						font-size: 31rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #555555;
						line-height: 1;
					}

					.img {
						image {
							width: 90rpx;
							height: 90rpx;
							border-radius: 10rpx;
							margin-right: 20rpx;
						}
					}
				}
			}

			.height {
				height: 100rpx !important;
			}

			.user:last-child {
				border: none;
			}
		}
		.setname {
			background: #FFFFFF;
			width: 100%;
			position: fixed;
			bottom: 0;
			left: 0;
			padding: 40rpx 30rpx calc(30rpx + env(safe-area-inset-bottom));
			border-radius: 20rpx;
			.form {
				.name {
					margin-right: 50rpx;
				}
		
				.input {
					width: 100%;
				}
			}
		
			.but {
				height: 80rpx;
				border-radius: 45rpx;
				background-color: #0265EB;
				color: #FFFFFF;
				font-size: 28rpx;
				margin-top: 50rpx;
			}
		}
		.uploads{
			background: #FFFFFF;
			width: 100%;
			position: fixed;
			bottom: 0;
			left: 0;
			padding-bottom: calc(30rpx + env(safe-area-inset-bottom));
			border-radius: 20rpx;
			.but {
				width: 100%;
				height: 80rpx;
				border-radius: 45rpx;
				background-color: #0265EB;
				color: #FFFFFF;
				font-size: 28rpx;
				margin-top: 50rpx;
			}
		}
		.select0{
			position: fixed;
			bottom: 0;
			.select1 {
				display: flex;
				background-color: white;
				.sex {
					height: 96rpx;
					line-height: 96rpx;
					font-size: 32rpx;
					font-family: "PingFangSC, PingFangSC-Medium";
					font-weight: 500;
					text-align: center;
					color: #323233;
					flex: 1;
					padding-left: 90rpx;
				}

				.confirm {
					height: 96rpx;
					line-height: 96rpx;
					font-size: 30rpx;
					font-family: "PingFangSC, PingFangSC-Regular";
					text-align: center;
					color: #3388ff;
					padding-right: 32rpx;
				}

				
			}
			.picker-view {
				width: 100vw;
				height: 600rpx;
			
				.item {
					height: 50px;
					align-items: center;
					justify-content: center;
					text-align: center;
				}
			}
		}
	}
</style>
